﻿<UserControl x:Class="EraDeiFessi.Controls.SubtitleSearch" x:Name="ss1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:actb="http://wpfcontrols.com/"
             xmlns:myControls="clr-namespace:EraDeiFessi.Controls"
             xmlns:myHelpers="clr-namespace:EraDeiFessi.Helpers"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="600">
    <!--<UserControl.Resources>
        <BooleanToVisibilityConverter x:Key="bool2vis"/>
        <myHelpers:BooleanToVisibilityConverter x:Key="invBool2Vis" True="Collapsed" False="Visible"/>
        <myHelpers:DoubleOffsetter x:Key="tvStretcher"/>

        <Style x:Key="AlternatingListViewItemStyle" TargetType="{x:Type TreeViewItem}">
            <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=OneWay}"/>
        </Style>

        <Style x:Key="borderStyle" TargetType="{x:Type Border}">
            <Style.Resources>
                <SolidColorBrush x:Key="hoverBrush" Opacity=".1" Color="{DynamicResource {x:Static SystemColors.HotTrackColorKey}}"/>
                <SolidColorBrush x:Key="hoverBorderBrush" Opacity=".6" Color="{DynamicResource {x:Static SystemColors.HotTrackColorKey}}"/>
            </Style.Resources>

            <Setter Property="BorderThickness" Value="1"/>
                <Setter Property="BorderBrush" Value="Transparent"/>
                <Style.Triggers>
                    <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
                            <Condition Binding="{Binding RelativeSource={RelativeSource Self},
                                                  Path=IsMouseOver}" Value="True"/>
                            <Condition Binding="{Binding RelativeSource={RelativeSource AncestorType=TreeViewItem},
                                                  Path=IsSelected}" Value="False"/>
                        </MultiDataTrigger.Conditions>
                    <Setter Property="Background" Value="{DynamicResource hoverBrush}"/>
                    <Setter Property="BorderBrush" Value="{DynamicResource hoverBorderBrush}"/>
                    </MultiDataTrigger>
                </Style.Triggers>
        </Style>
    </UserControl.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center"  Margin="2 10 2 2" x:Name="stackSearchBar">
            <actb:AutoCompleteTextBox x:Name="actb" Width="300" Margin="2"  KeyDown="actb_KeyDown" TextChanged="actb_TextChanged_2"/>
            <TextBlock Text="Lingua di ricerca: " Margin="2"/>
            <RadioButton Content="Inglese" Margin="2" x:Name="chkEnglish" IsChecked="True" VerticalAlignment="Center"/>
            <RadioButton Content="Italiano" Margin="2" x:Name="chkItalian" VerticalAlignment="Center"/>
            <Button Content="Cerca" Margin="2" Width="80" x:Name="buttonSearch" IsEnabled="False" Click="buttonSearch_Click"/>
        </StackPanel>

        <TabControl ItemsSource="{Binding ElementName=ss1, Path=Downloaders}" TabStripPlacement="Left" Grid.Row="1" Margin="2">
            <TabControl.ItemContainerStyle>
                <Style TargetType="TabItem">
                    <Setter Property="Header" Value="{Binding Header}"/>
                </Style>
            </TabControl.ItemContainerStyle>

            <TabControl.ContentTemplate>
                <DataTemplate>
                    <TreeView Margin="2" x:Name="treeResults" ItemsSource="{Binding Results}" HorizontalContentAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled" AlternationCount="2" ItemContainerStyle="{StaticResource AlternatingListViewItemStyle}">
                        <TreeView.Resources>
                            <HierarchicalDataTemplate DataType="{x:Type myControls:SubtitleWrapper}" ItemsSource="{Binding DownloadedFiles}">
                                <Border Style="{StaticResource borderStyle}">
                                    
                                    
                                    <Grid HorizontalAlignment="Stretch" Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeView}}, Path=ActualWidth, Converter={StaticResource tvStretcher}, ConverterParameter=-50}">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>

                                    <TextBlock FontWeight="Bold" Text="{Binding FileName}" Margin="2" VerticalAlignment="Center"/>

                                    <StackPanel Orientation="Horizontal" Margin="2 2 2 2" Height="30" HorizontalAlignment="Right" Grid.Column="1" >
                                        <Button Margin="2" Width="90" Height="25" x:Name="btnDownload" Click="btnDownload_Click" HorizontalAlignment="Right" Visibility="{Binding ShowDownloadButton, Converter={StaticResource bool2vis} }">
                                            <StackPanel Orientation="Horizontal">
                                                <myControls:AutoGreyableImage Source="..\Resources\icon_download.png" Margin="2"/>
                                                <TextBlock Margin="2" VerticalAlignment="Center">Scarica</TextBlock>
                                            </StackPanel>
                                        </Button>
                                        <myControls:LoadingPanel HorizontalAlignment="Center" Margin="2 2 30 2" Loaded="LoadingPanel_Loaded" Visibility="{Binding Downloading, Converter={StaticResource bool2vis}}"/>
                                    </StackPanel>
                                </Grid>
                                </Border>
                                
                            </HierarchicalDataTemplate>

                            <DataTemplate DataType="{x:Type myControls:SubtitleFileWrapper}">
                                <Border Style="{StaticResource borderStyle}">
                                    <Grid HorizontalAlignment="Stretch" Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TreeView}}, Path=ActualWidth, Converter={StaticResource tvStretcher}, ConverterParameter=-70}">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*"/>
                                        </Grid.ColumnDefinitions>
                                        <StackPanel Orientation="Horizontal" ToolTip="Trascina e rilascia (in una cartella per salvare, su un media player per caricare direttamente)" MouseMove="StackPanel_MouseMove">
                                            <TextBlock Text="{Binding FileName}" Margin="2" />
                                        </StackPanel>
                                    </Grid>
                                </Border>
                            </DataTemplate>
                        </TreeView.Resources>
                    </TreeView>
                </DataTemplate>
            </TabControl.ContentTemplate>
        </TabControl>
        
        <TextBlock Margin="2" Grid.Row="2" HorizontalAlignment="Center" TextWrapping="Wrap" Text="Una volta scaricato un sottotitolo puoi trascinarlo e rilasciaro direttamente su un media player in esecuzione per caricarlo (oppure trascina in una cartella per copiarlo)"/>
    </Grid>-->
</UserControl>
